package com.pengtu.entity.app;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.User;

/**
 * 权限.
 * 
 * 注释见{@link User}.
 * 
 * @author calvin
 */
@Entity
@Table(name = "T_APP_AUTHORITY")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Authority extends IdEntity {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6666867111486974278L;

	/**
	 * SpringSecurity中默认的角色/授权名前缀.
	 */
	public static final String AUTHORITY_PREFIX = "ROLE_";
	
	private String autName;
	private String category;
	
	public Authority() {
	}

	public Authority(String id, String autName) {
		this.id = id;
		this.autName = autName;
	}

	@Column(name="AUTNAME")
	public String getAutName() {
		return autName;
	}

	public void setAutName(String autName) {
		this.autName = autName;
	}
	
	@Transient
	public String getPrefixedName() {
		return AUTHORITY_PREFIX + autName;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
	
	@Column(name="CATEGORY")
	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}
}
